<template>
  <div class="dialog-view">
    dialog-view ios-windows
    <el-input
      size="small"
      v-model="mileage"
      @input="getMileageInput"
      @change="getMileageChange"
      clearable
      placeholder="里程"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      mileage: "",
    };
  },
  methods: {
    getMileageInput(val) {
      if (Number(val)) {
        let part = val.toString().split(".")[1];
        if (part && part.length >= 3) {
          this.mileage = parseInt(val * 1000) / 1000;
        }
      } else {
        this.mileage = val.substr(0, val.length - 1);
      }
    },
    getMileageChange(val) {
      if (val && Number(val)) {
        let arr = val.toString().split(".");
        arr[1] = arr[1] ? arr[1] : "";
        arr[1] = arr[1].padEnd(3, 0);
        this.mileage = arr.join(".");
      }
    },
  },
};
</script>
<style lang="scss" scoped>
</style>